package jdbcinterface;

import java.sql.*;

import rmi.ConnectionAdapter;
import rmi.RemoteConnection;
import rmi.RemoteStatement;


public class GoggleConnection extends ConnectionAdapter {
	private RemoteConnection rconn;

	public GoggleConnection(RemoteConnection c) {
		rconn = c;
	}

	public Statement createStatement() throws SQLException {
		try {
			RemoteStatement rstmt = rconn.createStatement();
			return new GoggleStatement(rstmt);
		}
		catch(Exception e) {
			throw new SQLException(e.toString() );
		}
	}
	@Override
	public PreparedStatement prepareStatement(String sql) throws SQLException {
		try
		{
			RemoteStatement rstmt = rconn.createStatement();
			return new GogglePreparedStatement(new GoggleStatement(rstmt),sql,rconn);
		}
		catch (Exception e) {
			throw new SQLException(e.toString() );// TODO: handle exception
		}

	}
	public void close() throws SQLException {
		try {
			rconn.close();
		}
		catch(Exception e) {
			throw new SQLException(e.toString() );
		}
	}
	
	public void commit () throws SQLException {
		try {
			rconn.commit();
		}
		catch(Exception e) {
			throw new SQLException(e.toString() );
		}
	}

	public void rollback () throws SQLException {
		try {
			rconn.rollback();
		}
		catch(Exception e) {
			throw new SQLException(e.toString() );
		}
	}

	public void setAutoCommit(boolean autoCommit) throws SQLException {
		try { 
			rconn.setAutoCommit( autoCommit ) ;
		}catch ( Exception e ) {
			throw new SQLException ( e.toString() ) ; 
		}
	}
	
	public boolean getAutoCommit() throws SQLException {
		try {
			return rconn.getAutoCommit();
		}catch ( Exception e ) { 
			throw new SQLException ( e.toString () ) ; 
		}
	}
	
	public DatabaseMetaData getMetaData() throws SQLException {
		try {
			return new GoggleDBMeta ( rconn.getDBMeta() ) ;
		}catch ( Exception e ) {
			throw new SQLException ( e.toString () ) ; 			
		}
	}
	
}

